package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.logic.helper.UnionActivityGroupHelper;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.twins.TwinsModule;
import com.yanqu.road.server.manger.activity.twins.TwinsMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class UseRecoverTwinsPvpHpPower extends BaseUseGoods {

    public UseRecoverTwinsPvpHpPower(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }

    @Override
    int checkUse(long count) {
        if(!SystemOpenMgr.systemOpen(player, eSystemId.TwinsActivity.getValue())){
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        int activityId = TwinsMgr.getActivityId();
        if (activityId == 0){
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, player.getUserId());
        if (groupId == UnionActivityGroupHelper.NO_GROUP_ID){
            return GameErrorCode.E_TWINS_NO_GROUP;
        }
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        long reValue = goodsInfo.getParamList().get(0).longValue();
        //不会没配吧我日，没配就恢复1
        if(reValue == 0){
            reValue = 1;
        }
        player.getModule(TwinsModule.class).pvpHpAdd( reValue * count);
        return new UseGoodsResult();
    }
}
